package vip.meeet.jdk.gc;

import java.util.concurrent.TimeUnit;

public class FinalizeEscape {

    private static FinalizeEscape finalizeEscape;

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("finalize method");
        finalizeEscape = this;
    }

    public static void main(String[] args) throws InterruptedException {
        finalizeEscape = new FinalizeEscape();
        finalizeEscape = null;
        System.gc();
        TimeUnit.SECONDS.sleep(1);
        System.out.println(finalizeEscape == null);
        finalizeEscape = null;
        System.gc();
        TimeUnit.SECONDS.sleep(1);
        System.out.println(finalizeEscape == null);

    }
}
